<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="ookweb.Conn"%>
<%@ page import="ookweb.Data"%>
<%@ include file="../public.jsp" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/ookweb/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">    
    <title>文件列表管理</title>    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/images/m/css.css">
	<script src="<%=basePath%>js/jquery-1.5.1.min.js"  type="text/javascript" ></script>
	<script src="<%=basePath%>js/public.js"  type="text/javascript" ></script>
  </head>
  
  <body><br/>
  <%   Data data=new Data(dbuser,dbpass,dburl);
     Conn con=new Conn(dbuser,dbpass,dburl);
      String fid=(String)request.getParameter("fid");
      String act=(String)request.getParameter("act"); 
      String flid=(String)request.getParameter("flid");
    if("".equals(fid)||fid==null){fid="0";}
    //分页段 
     //变量声明 
    
String mysql=new String(); //SQL语句
mysql=" web_filelist where flid > 0 ";
String where="";
if(!("0".equals(fid)) && fid!=null){
mysql=mysql+" and fid="+fid;
where=where+" and fid="+fid;
}

int intRowCount=0;  //总的记录数
int intPageCount=0; //总的页数
int intPageSize=15; //每页显示的记录数
int intPage; //待显示页码 
String strPage=new String(); //用来接收当页码参数
int begin_no=0; //开始的rownum记录号
int end_no=0;  //结束的rownum记录号

//取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){//表明在QueryString中没有page这一个参数，此时显示第一页数据 
intPage = 1; 
} 
else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} 
//得到总的数据记录行数
intRowCount=data.getRowCount(mysql); //总记录数

//计算总共要分多少页
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 

if(intPage>intPageCount) intPage = intPageCount; 
//分页段
     

     
     
    
    int intT=0;
    if("d".equals(act) && !("".equals(fid)) && fid!=null){
       data.delete("delete from web_filelist where fllid="+fid);
       act=""; 
     }
    if(!("".equals(act) ||  act==null)){
       String title="",filepath="",info="",nums="",ver="";
      if("save".equals(act)){
          String sql="";
          filepath=(String)request.getParameter("filepath");
          title=(String)request.getParameter("title");
          info=(String)request.getParameter("info");
          nums=(String)request.getParameter("nums");
          ver=(String)request.getParameter("ver");
         
         int num=0;
         
         if(!("".equals(flid)) && flid!=null){
	         sql="update web_filelist set title='"+title+"',filepath='"+filepath+"',info='"+info+"',ver='"+ver+"' where flid="+flid;
	         num=data.update(sql);
	         if(num>0){out.print("<script>alert(\"已成功修改\");</script>");}
         }else{
         java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy-MM-dd");
         java.util.Date currentTime=new java.util.Date();
         String time=formatter.format(currentTime);
         sql="insert into web_filelist(flid,fid,title,info,filepath,ver,addtime)values(WEB_HDP_SEQ.nextval,"+fid+",'"+title+"','"+info+"','"+filepath+"','"+ver+"',to_date('"+time+"','yyyy/mm/dd'))";
         num=data.insert(sql);
         if(num>0){out.print("<script>alert(\"已成功添加\");</script>");}
          act="";
         }
         response.sendRedirect(basePath+"webadmin/info/dowfile.jsp?fid="+fid+"&page"+intPage);
      }else if("e".equals(act) && !("".equals(flid)) && flid!=null){	       
			 ResultSet rs=con.getRs("SELECT * FROM web_filelist where flid="+flid);
			 if(rs.next()){
			 title=rs.getString("title");fid=rs.getString("fid");
			 filepath=rs.getString("filepath");info=rs.getString("info");
			 flid=rs.getString("flid");ver=rs.getString("ver");
			 }
      }else{flid="";}
      
      %>
   
      <script type="text/javascript" src="<%=basePath%>ckfinder/ckfinder.js"></script>
      
      <form action="<%=basePath%>webadmin/info/dowfile.jsp?act=save&flid=<%=flid %>&fid=<%=fid%>&page=<%=intPage %>" method="post" id="frm">
	  <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
	   <tr>
	    <td align="center" width="140">标题</td>
	    <td align="left"><input name="title" id="title" style="width:400px;" type="text" class="inp" value="<%=title %>"/></td>
	  </tr>
	   <tr> 
	    <td align="center" width="140">文件</td>
	    <td align="left"><input name="filepath" id="filepath" style="width:350px;" type="text" class="inp" value="<%=filepath %>"/>
        <input type="button" value="浏览" onclick="BrowseServer( 'Files:/', 'filepath' );" /></td>
	  </tr>
	   
	  <tr>
	    <td align="center" width="140">简介</td>
	    <td align="left"><textarea name="info" style="height:60px;width:400px;"><%=info %></textarea></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">版本</td>
	    <td align="left"><input name="ver" id="ver" style="width:400px;" type="text" class="inp" value="<%=ver %>"/></td>
	  </tr>
	   <tr>
	    <td align="center" width="140">操作</td>
	    <td align="left"> <input name="cmd" id="savecmd" type="button" class="inp" value="保存" style="width:60px;"/> <input name="cmd" id="cmdreturn" type="button" class="inp" value="返回" style="width:60px;"/></td>
	  </tr>
	 </table>
	 </form>
   <script type="text/javascript">
	$(document).ready(function() {
		$('#savecmd').click(function() {
		  if($('#title').attr('value')==''){
		  alert('请输入标题');return;
		  }else if($('#filepath').attr('value')==''){
		  alert('请选择路径');return;
		  }else{
		    $("#frm").submit();
		  }
		});
		$('#cmdreturn').click(function() {
		window.history.back();
		});
	});
	
	function BrowseServer( startupPath, functionData )
{

	var finder = new CKFinder();

	finder.basePath = '../';

	finder.startupPath = startupPath;

	finder.selectActionFunction = SetFileField;

	finder.selectActionData = functionData;

	finder.selectThumbnailActionFunction = ShowThumbnails;

	finder.popup();
}

function SetFileField( fileUrl, data )
{
	document.getElementById( data["selectActionData"] ).value = fileUrl;
}

function ShowThumbnails( fileUrl, data )
{
	var sFileName = this.getSelectedFile().name;
	document.getElementById( 'thumbnails' ).innerHTML +=
			'<div class="thumb">' +
				'<img src="' + fileUrl + '" />' +
				'<div class="caption">' +
					'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
				'</div>' +
			'</div>';

	document.getElementById( 'preview' ).style.display = "";
	return false;
}
   </script>
   <% }else{%>
  【<span class="bt">信息管理</span>】
 《<a href="<%=basePath%>webadmin/info/dowfile.jsp?act=a&fid=<%=fid %>" title="增加新文件信息" rel="gb_page_center[600,300]">添加新文件</a>》
 <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
  <tr>
    <th >标题</th>
    <th width="140">时间</th>
    <th width="140">操作</th>
  </tr>
  <% 
  if(intRowCount>0){
	    begin_no=(intPage-1) * intPageSize + 1; 
        end_no = intPage * intPageSize;
	    mysql="select a.* from (select rownum row_id ,flid,fid,title,addtime from (select flid,fid,title,addtime from web_filelist where flid>0 "+where+" order by flid desc)) a";
	    mysql=mysql+"  where row_id between " +begin_no+ " and " +end_no;
	   //out.print(mysql);
	    ResultSet rs=con.getRs(mysql);
		int i=0;
		String title="";
		String sflid="";
		while(rs.next()){
		i++;title=rs.getString("title");
		sflid=rs.getString("flid");
	 %>
	<tr onmouseover='$(this).css({"background":"#cee1ed"});' onmouseout='$(this).css({"background":"#fff"});'>
    <td  align="left"><%=title %></td>
    <td width="140" align="center"><%=rs.getDate("addtime") %></td>
    <td width="140" align="center">
    <span class="area"><a title="<%=title %>_修改"  href="<%=basePath%>webadmin/info/dowfile.jsp?act=e&page=<%=intPage %>&fid=<%=fid %>&flid=<%=sflid%>"> 编辑 </a></span> 
    <span class="area"><a href="javascript:confirmDelete('<%=basePath%>webadmin/info/dowfile.jsp?act=d&flid=<%=sflid%>&fid=<%=fid %>&page=<%=intPage %>');"> 删除 </a></span></td>
    </tr>
   <%} 
   if(intPageCount>1){
   %>
   <tr>
    <td colspan="5" align="center">
     第<%=intPage%>页 共<%=intPageCount%>页 
<a href="<%=basePath%>webadmin/info/dowfile.jsp?page=1&fid=<%=fid %>">首页</a>
<%if(intPage>1){%><a href="<%=basePath%>webadmin/info/dowfile.jsp?page=<%=intPage-1%>&fid=<%=fid %>">上一页</a><%}%> 
<%if(intPage<intPageCount){%><a href="<%=basePath%>webadmin/info/dowfile.jsp?page=<%=intPage+1%>&fid=<%=fid %>">下一页</a><%}%> 
<a href="<%=basePath%>webadmin/info/dowfile.jsp?page=<%=intPageCount%>&fid=<%=fid %>">尾页</a>
   </td>
   </tr>
   <%} %>
 </table>
 <% } } con.close();%>
  </body>
</html>
